package com.qiangqiang.controller;

import com.qiangqiang.dto.BanDTO;
import com.qiangqiang.service.BanService;
import com.qiangqiang.util.ResultVOUtil;
import com.qiangqiang.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by q on 2018/3/30.
 */
@RestController
@RequestMapping("/ban")
public class BanController {

    @Autowired
    private BanService banService;

    @RequestMapping("/add")
    public ResultVO addBanRecord(@RequestParam("id") String dId,
                                 @RequestParam("goods") String goods){
        banService.addBanRecord(dId,goods);
        return ResultVOUtil.success();
    }

    @RequestMapping("/findAll")
    public ResultVO<Page<BanDTO>> findAllBans(@RequestParam(value = "page", defaultValue = "0") int page,
                                              @RequestParam(value = "size",defaultValue = "10") int size){
        return ResultVOUtil.success(banService.findAllBans(page,size));
    }

    @RequestMapping("/findByDId")
    public ResultVO<List<BanDTO>> findByDId(@RequestParam("dId") String dId){
        return ResultVOUtil.success(banService.findByDId(dId));
    }
}